<?php 
/*************************************************************************************
 * dbaccess.php
 * -----------
 * phpGMapTrips 
 * 
 * This php application allows you to easily record your travel destinations 
 * and display them with Google maps.
 * 
 * Author: Stephane Coste (lescoste@gmail.com)
 * Copyright: (c) 2006 Stephane Coste (http://lescoste.net/)
 * Release Version: 0.1
 * CVS Revision Version: $Revision: 1.1 $
 * Date Started: 2006/02/19
 * Last Modified: $Date: 2007/02/13 05:48:43 $
 *
 *************************************************************************************
 *
 *     This file is part of phpGMapTrips.
 *
 *   phpGMapTrips is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   phpGMapTrips is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with phpGMapTrips; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ************************************************************************************/
?>
<?php 
/*
xml data exemple
TODO write xml schema or DTD
<points>
<point name="Hearst castle" lat="35.685053" long="-121.168213"  url="http://homeip.net/gallery/californie91" trips="California"><moreinfo name="date">20061201</moreinfo><moreinfo name="address">paris france</moreinfo>
<photos> <photo url="http://homeip.net/albums/californie91/Hearst_castle.thumb.jpg" /> </photos>
</point>
</points>


<trips>
<trip name="tunisie" groups="Africa; north africa"> 
<point name="" seq="1" /> // if the name is filled use it to find the lat/long else use lat/long
<point name="" seq="2" lat="" long=""/>
<point name="" seq="3" />
</trip>
</trips>

*/
//error_reporting(E_ALL);
include_once("commondb.php");

/************
* Public functions 
************/

// @return trips array : key = group name, value = list of trips
function getGroups() {
	global $db_grouparray;
	$db_grouparray = array();
	parseGroupData();
	ksort($db_grouparray);
	reset($db_grouparray);
	return $db_grouparray;
}

// @return trips array : key = trip, value = number of points
function getTripSummary() {
	global $db_triparray, $f_files, $db_tripNamearray, $tripname;
	$db_triparray = array();
		parseTripsData();
	ksort($db_triparray);
	reset($db_triparray);
	return $db_triparray;
}

function getTripPoints($atripname) {
	global $db_pointarray, $tripname, $f_files;
	$tripname = $atripname;
	$db_pointarray = array();
		parsePointsData();
	return $db_pointarray;
}

// find the latests added points
function getLatestPoints() {
	global $db_datearray, $findlatest;
	$findlatest = true;
	$db_datearray = array();
	parsePointsData();
	$findlatest = false;
	return $db_datearray;
}

// search points with this in their name
function searchPoints($asearch) {
	global $db_pointarray, $search;
	$search = $asearch;
	$db_pointarray = array();
	parsePointsData();
	return $db_pointarray;
}

// load all points names that starts with name
function getPointsNames($name) {
	global $pointsNames, $loadAllNames, $rootname;
	$loadAllNames = true;
	$rootname = $name;
	$pointsNames = array();
	parsePointsData();
	return $pointsNames;
}

// record a new point
function savePoint($fpw, $hasBeenSaved, $editName, $editNewname, $editLat, $editLng, $editUrl, $editPhotoUrl, $editTags, $editMoreinfo){
	global $editedPoint, $pointsNames;

	$editedPoint["oldname"] = $editName;
	$editedPoint["newname"] = $editNewname;
	$editedPoint["lat"] = $editLat;
	$editedPoint["lng"] = $editLng;
	$editedPoint["url"] = $editUrl;
	$editedPoint["photo"] = $editPhotoUrl;
	$editedPoint["tags"] = $editTags;
	$editedPoint["moreinfo"] = $editMoreinfo;
	$editedPoint["hasBeenSaved"] = $hasBeenSaved;
	$editedPoint["fpw"] = $fpw;

	$pointsNames = getPointsNames($editedPoint["newname"]);
	
	parseAndCopyPointData();

	return $editedPoint["hasBeenSaved"];
}

?>
